package com.example.wlzz.controller;
import com.example.wlzz.dto.BestMajorDTO;
import com.example.wlzz.repository.SchoolRepository;
import com.example.wlzz.repository.mapper.ExcelMajorMapper;
import com.example.wlzz.service.SchoolService;
import com.example.wlzz.utils.ResultVOUtil;
import com.example.wlzz.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/school")
@Slf4j
@Api(tags = "学校模块(预设)")
public class SchoolController {
    @Autowired
    private SchoolRepository schoolRepository;
    @Autowired
    private SchoolService schoolService;
    @Autowired
    private ExcelMajorMapper excelMajorMapper;  //Idea报错
    @PostMapping("/getAllSchool")
    @ApiOperation("获取所有学校")
    public ResultVO first(@ApiParam("token") @RequestParam("token") String token){
         return ResultVOUtil.success(schoolRepository.findAll());
    }
    @PostMapping("/getHightSchool")
    @ApiOperation("获取高校排行")
    public ResultVO getHightSchool(@ApiParam("token") @RequestParam("token") String token,
                                   @ApiParam("当前页数(第0页开始)") @RequestParam("page") Integer page,
                                   @ApiParam("限制条数") @RequestParam("size") Integer size) {
        PageRequest request = PageRequest.of(page,size);
        return ResultVOUtil.success(schoolService.findByHightSchool(request));
    }
    @PostMapping("/getBestMajor")
    @ApiOperation("获取类别")
    public ResultVO getMajor(@ApiParam("token") @RequestParam("token") String token){
        List<String> list = excelMajorMapper.getMainCateory();
        List<BestMajorDTO> bestMajorDTOS = new ArrayList<>();
        for (String s : list) {
            BestMajorDTO bestMajorDTO = new BestMajorDTO();
            bestMajorDTO.setBestMajor(s);
            bestMajorDTO.setSubMajor(excelMajorMapper.getSubCateory(s));
            bestMajorDTOS.add(bestMajorDTO);
    }
        return ResultVOUtil.success(bestMajorDTOS);
    }
    @PostMapping("/getMajor")
    @ApiOperation("获取类别中的专业")
    public ResultVO getSubMajor(@ApiParam("token") @RequestParam("token") String token,
                                @ApiParam("这里需要填写的子类别") @RequestParam("subMajor") String subMajor){
        return ResultVOUtil.success(excelMajorMapper.getMajor(subMajor));
    }
}
